<head>
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
    <script src="${ctx}/js/extends.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <script src="${ctx}/js/util.js"></script>
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
</head>
<title>新老用户每日必赚次数配置分页</title>
<div class="lay-box">
    <button class="layui-btn" onclick="gradeEdit()">
        <i class="layui-icon">&#xe608;</i> 添加
    </button>
    <div class="layui-inline" style="margin: 0 0 8px 20px;">
        <label class="layui-form-label" style="width: 95px">起始时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="star" placeholder="请选择时间">
        </div>
    </div>
    <div class="layui-inline" style="margin: 0 0 8px 20px;">
        <label class="layui-form-label" style="width: 95px">结束时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="end" placeholder="请选择时间">
        </div>
    </div>
    <div style="width: 180px;display: inline-block;margin: 0 0 8px 20px;">
        <input type="text" name="imei" id="imei" required lay-verify="required" placeholder="请输入设备号"
               autocomplete="off"
               class="layui-input">
        <input type="text" name="version" id="version" required lay-verify="required" placeholder="请输入版本号"
               autocomplete="off"
               class="layui-input">
        <input type="text" name="appStore" id="appStore" required lay-verify="required" placeholder="请输入渠道"
               autocomplete="off"
               class="layui-input">
    </div>
    <span onclick="search()" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">查询</span>
    <span onclick="blackrecord()" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">批量封禁</span>
    <table class="table table-border table-bordered table-hover table-bg table-sort" id="layTable"
           lay-filter="tableFilter">

    </table>
</div>

<style>
    .lay-box {
        padding: 8px 12px;
    }

    .layui-form-checkbox[lay-skin=primary] i {
        top: 5px;
    }
</style>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="save">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<!--请在下方写此页面业务相关的脚本-->

<script type="text/javascript">
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#star'
            , type: 'datetime'

        });
        laydate.render({
            elem: '#end'
            , type: 'datetime'

        });
    });
    var startDate = "";
    var endDate = "";
    var searchKey = "";
    var tableIns;
    var ids = "";
    var form;
    var table = "tb_app_version";
    layui.use('table', function () {
        tableIns = layui.table,
            form = layui.form;
        form.render();
        tableIns.render({
            elem: '#layTable'
            ,
            url: '/apps/logs/list'
            ,
            method: 'POST'
            ,
            where: {
            }
            ,
            id: 'dataTableId'
            ,
            cols: [[
                {type: 'checkbox', field: 'id'}
                , {
                    field: 'createTime',
                    title: '请求时间',
                    align: 'center',
                    width: 200,
                    sort: true
                }, {
                    field: 'ipAddr',
                    title: 'ipAddr',
                    align: 'center',
                    width: 200,
                    sort: true
                }


                , {
                    field: 'imei',
                    title: '设备号',
                    width: 150,
                    align: 'center',
                    sort: true
                }, {
                    field: 'appStore',
                    title: '应用市场',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'brand',
                    title: 'brand',
                    width: 150,
                    align: 'center',
                    sort: true
                }

                , {
                    field: 'memberId',
                    title: '用户id',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'macAddr',
                    title: 'macAddr',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'os',
                    title: 'os',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'osv',
                    title: 'osv',
                    width: 150,
                    align: 'center',
                    sort: true
                }

                , {
                    field: 'version',
                    title: '版本号',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'ua',
                    title: 'ua',
                    width: 100,
                    align: 'center',
                    sort: true
                }
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150, align: 'center'}

            ]]
            ,
            page: true
        });

        form.on('switch(appMode)', function (obj) {
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            if (obj.elem.checked) {
                commonenable(this.value, "Beta", "app_mode");
            } else {
                commonenable(this.value, "Debug", "app_mode");
            }

        });
        form.on('switch(forceUpdate)', function (obj) {
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            if (obj.elem.checked) {
                commonenable(this.value, "True", "force_update");
            } else {
                commonenable(this.value, "False", "force_update");
            }

        });
        form.on('switch(tipUser)', function (obj) {
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            if (obj.elem.checked) {
                commonenable(this.value, "True", "tip_user");
            } else {
                commonenable(this.value, "False", "tip_user");
            }

        });
        form.on('switch(openControl)', function (obj) {
            var k = 0;
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            if (obj.elem.checked) {
                k = 1;
            } else {
                k = 0;
            }
            $.ajax({
                url: "/apps/apps/control",
                type: 'post',
                data: {"id": this.value, "status": k},
                async: false,
                dataType: "json",
                success: function (arg) {
                    if (arg.success) {
                        layer.msg(arg.message);
                        search();
                    } else {
                        layer.msg(arg.message);
                    }
                }
            });

        });

        // tableIns.on('checkbox(tableFilter)', function (obj) {
        //     var checkStatus = tableIns.checkStatus('dataTableId');
        //     var dataList = checkStatus.data;
        //     if (dataList != null && dataList.length > 0) {
        //
        //         for (var i = 0; i < dataList.length; i++) {
        //             ids += dataList[i].id + ",";
        //         }
        //     }
        // });

        function deleteId(ids) {
            if (ids != "") {
                $.ajax({
                    url: "/sys/tbappversion/delete",
                    type: 'post',
                    data: {"id": ids},
                    async: false,
                    dataType: "json",
                    success: function (arg) {
                        if (arg) {
                            layer.msg(arg.message);
                            search();
                        } else {
                            layer.msg(arg.message);
                        }
                    }
                });
            }
        }

        $("#multiDelete").click(function () {
            deleteId(ids)
        });

        tableIns.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    deleteId(data.id)
                    layer.close(index);
                });
            } else if (obj.event === 'save') {
                window.parent.iw.dialog({
                    size: 'lg',
                    title: '编辑版本',
                    href: '/apps/edit/' + data.appStore + '/' + data.innerCode,
                    closing: function () {
                        table.bootstrapTable('refresh');
                    }
                });
            }
        });
    });

    function search() {
        var imei=$("#imei").val();
        var version=$("#version").val();
        var appStore=$("#appStore").val();
        startDate = $("#star").val();
        endDate = $("#end").val();
        tableIns.reload('dataTableId', {
            where: {
                'star': startDate, 'end': endDate,imei:imei,version:version,appStore:appStore
            }
            , page: {
                curr:1
            }
        });
    }


    function gradeEdit() {
        window.parent.iw.dialog({
            size: 'lg',
            title: '发布版本',
            href: '/apps/insert',
            closing: function () {
                search();
            }
        });
    }

    function showmsg(msg) {
        layer.msg(msg)
    }

    function commonenable(id, status, feild) {
        $.ajax({
            url: "/common/commonSwitch",
            type: 'post',
            data: {"table": table, "id": id, "status": status, "feild": feild},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    search();
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }
    function blackrecord() {
        var list="";
        var checkStatus = tableIns.checkStatus('dataTableId');
        var dataList = checkStatus.data;
        if (dataList != null && dataList.length > 0) {

            for (var i = 0; i < dataList.length; i++) {
                list += dataList[i]._id + ",";
            }
        }
        $.ajax({
            url: "/apps/black/data",
            type: 'post',
            data: { "str": list},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    search();
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }

</script>
<!--/请在上方写此页面业务相关的脚本-->
